package com.jackiechancinema.ssm.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jackiechancinema.ssm.dao.SalManageDao;
import com.jackiechancinema.ssm.dto.SalaryExcelDto;
import com.jackiechancinema.ssm.entity.Salary;
import com.jackiechancinema.ssm.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class SalaryReadListener extends AnalysisEventListener<SalaryExcelDto> {
    @Autowired
    private SalManageDao dao;

    private List<Salary> list=new ArrayList<Salary>();
    @Override
    public void invoke(SalaryExcelDto dto, AnalysisContext analysisContext) {
        Salary salary = BeanUtil.copyProperty(Salary.class, dto, dto.getClass().getDeclaredFields());
        list.add(salary);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

        int r=dao.insertBatch(list);
        list.clear();
    }
}
